PRINT N'Setting-up service broker';
GO
--
-- Work items service
-- This service receives new work that needs to be done.
--
CREATE MESSAGE TYPE 
	[http://schemas.codeflows.net/messages/workitems/enqueue] 
VALIDATION = NONE
GO

CREATE CONTRACT 
	[http://schemas.codeflows.net/contracts/workitems]
	([http://schemas.codeflows.net/messages/workitems/enqueue]
		SENT BY INITIATOR)
GO

CREATE QUEUE WorkItems
GO

CREATE SERVICE
       [http://schemas.codeflows.net/services/workitems]
       ON QUEUE WorkItems
       ([http://schemas.codeflows.net/contracts/workitems]);
GO

--
-- Failed items service
-- Service used to record all work items failed during dispatch
-- 
CREATE MESSAGE TYPE 
	[http://schemas.codeflows.net/messages/faileditems/retry] 
VALIDATION = NONE
GO

CREATE CONTRACT 
	[http://schemas.codeflows.net/contracts/faileditems]
	([http://schemas.codeflows.net/messages/faileditems/retry]
		SENT BY INITIATOR);
GO

CREATE QUEUE FailedItems
GO

CREATE SERVICE
       [http://schemas.codeflows.net/services/faileditems]
       ON QUEUE FailedItems
       ([http://schemas.codeflows.net/contracts/faileditems]);
GO

--
-- Control service
-- Service used to issue control commands 
-- such as execute retry or execute expired
-- 
CREATE MESSAGE TYPE 
	[http://schemas.codeflows.net/messages/control/retry] 
VALIDATION = NONE
GO

CREATE MESSAGE TYPE 
	[http://schemas.codeflows.net/messages/control/runexpired] 
VALIDATION = NONE
GO

CREATE MESSAGE TYPE 
	[http://schemas.codeflows.net/messages/control/runpartiallycompleted] 
VALIDATION = NONE
GO

CREATE CONTRACT 
	[http://schemas.codeflows.net/contracts/control]
	([http://schemas.codeflows.net/messages/control/retry] SENT BY INITIATOR,
	 [http://schemas.codeflows.net/messages/control/runpartiallycompleted] SENT BY INITIATOR);
GO

CREATE QUEUE [Control]
GO

CREATE SERVICE
       [http://schemas.codeflows.net/services/control]
       ON QUEUE [Control]
       ([http://schemas.codeflows.net/contracts/control]);
GO

--
-- Client service
-- Sender used for all one way communications
-- 
CREATE CONTRACT
	[http://schemas.codeflows.net/contracts/client]
	([DEFAULT] SENT BY ANY)
GO

CREATE QUEUE Client;
GO	

CREATE SERVICE
       [http://schemas.codeflows.net/services/client]
       ON QUEUE Client
       ([http://schemas.codeflows.net/contracts/client]);
GO
